$(function(){
    let layer = layui.layer
    $('#logout').on('click',function(){
     layer.confirm('确认退出吗?',{icon:3,title:'提示'},function(index){
      location.href='/login.html'
      localStorage.removeItem('token')
      layer.close(index)
     }
     )
    })
    getUserInfo()
   })
   function getUserInfo(){
    axios({
     method:'GET',
     url:'/my/userinfo',
    //  headers:{
    //   Authorization:localStorage.getItem('token')
    //  }
    }).then((res)=>{
    //  console.log(res.data);
     if(res.data.status !==0){
      return layui.layer.message
     }
   renderUserInfo(res.data.data)
    })
   }
   function renderUserInfo(user){
    let name = user.nickname||user.username
    $('.welcome').html('欢迎&nbsp;&nbsp;'+name)
    if(user.user_pic ==null){
     $('.avatar-text').show().html(name[0].toUpperCase())
     $('.avatar-img').hide()
    }else{
     $('.avatar-text').hide()
     $('.avatar-img').show().attr('src',user.user_pic)
    }
   }
   